package thread_ex;
class Bank{
	double money;
	public Bank(double m) {
		this.money=m;
	}

	public synchronized void input(int n){
		for(int i=0;i<=100;i++){
			System.out.print("입금처리중..");
			if(i%10 == 0) System.out.println();
		}
		money +=n;
		System.out.println("입금완료! (잔액 : " + money + " 원)");
	}

	public synchronized void output(int n){		
		for(int i=0;i<=100;i++){
			System.out.print("출금처리중..");
			if(i%10 == 0) System.out.println();
		}
		money -=n ;
		System.out.println("출금완료! (잔액 : " + money + " 원)");
	}
}

class InputThread extends Thread{
	Bank bank;
	
	public InputThread(Bank b){
		this.bank=b;
	}
	
	public void run(){
		bank.input(4000);
	}
}

class OutputThread extends Thread{
	Bank bank;
	
	public OutputThread(Bank b){
		this.bank=b;
	}
	
	public void run(){
		bank.output(400);
	}
}

public class Test01_synchronized {

	public static void main(String[] args) {
		Bank bank = new Bank(10000);
		new InputThread(bank).start();
		new InputThread(bank).start();
		new OutputThread(bank).start();

	}

}
